package org.xdq.新的两种线程的创建方式;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Test {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        Callable callable = new Callable() {
            @Override
            public Object call() throws Exception {
                for(int i=1;i<=100;i++){
                    System.out.println(Thread.currentThread().getName()+":"+i);
                    Thread.sleep(10);
                }
                return "大家好！";
            }
        };

        FutureTask futureTask = new FutureTask(callable);
        new Thread(futureTask).start();
        System.out.println("等待中.......");
        Object value = futureTask.get();//这是一个阻塞等待过程
        System.out.println(value);
    }
}
